/*
 * Copyright (c) 2008, Takashi Ito
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the authors nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "tansu_internal.h"
#include <wx/wx.h>
#include <wx/image.h>

#ifndef SOAPFRAME_H
#define SOAPFRAME_H

// begin wxGlade: ::dependencies
#include <wx/splitter.h>
#include <wx/listctrl.h>
#include <wx/notebook.h>
// end wxGlade

// begin wxGlade: ::extracode
enum {
    ID_SOAP_RESULT_LIST = 200,
    ID_SOAP_EXECUTE,
    ID_SOAP_CANCEL,
    ID_SOAP_CLEAR,
    ID_SOAP_EXIT,
};
// end wxGlade

#include <wx/listctrl.h>
#include "UpnpFrame.h"
#include "SoapResult.h"

WX_DECLARE_LIST(wxStaticText, LabelList);
WX_DECLARE_LIST(wxTextCtrl, TextList);

class SoapFrame: public wxFrame {
public:
    // begin wxGlade: SoapFrame::ids
    // end wxGlade

    SoapFrame(struct event_base *evbase,
              const wxString& action_name,
              int option,
              const struct tansu_cp_device *cp_device,
              const struct tansu_cp_service *cp_service,
              wxWindow* parent,
              int id,
              const wxString& title,
              const wxPoint& pos=wxDefaultPosition,
              const wxSize& size=wxDefaultSize,
              long style=wxDEFAULT_FRAME_STYLE);

    virtual ~SoapFrame();

private:
    // begin wxGlade: SoapFrame::methods
    void set_properties();
    void do_layout();
    // end wxGlade

protected:
    // begin wxGlade: SoapFrame::attributes
    wxStatusBar* frame_2_statusbar;
    wxStaticText* label_1;
    wxListCtrl* list_ctrl_info;
    wxPanel* window_2_pane_1;
    wxStaticText* label_2;
    wxListCtrl* list_ctrl_result;
    wxPanel* window_2_pane_2;
    wxSplitterWindow* window_2;
    wxScrolledWindow* panel_in;
    wxTextCtrl* text_ctrl_in;
    wxNotebook* notebook_1;
    wxButton* button_exec;
    wxButton* button_cancel;
    wxButton* button_clear;
    wxButton* button_exit;
    wxScrolledWindow* panel_out;
    wxTextCtrl* text_ctrl_out;
    wxNotebook* notebook_2;
    wxScrolledWindow* window_1_pane_2;
    wxSplitterWindow* window_1;
    // end wxGlade

    DECLARE_EVENT_TABLE();

    void SetValues();
    void SetArguments(struct tdom_elem *action);
    void SetArgumentValues(wxTextCtrl& text_ctrl,
                           LabelList& labels,
                           TextList& texts,
                           struct tdom_doc *doc,
                           struct evkeyvalq *headers = NULL);
    wxFlexGridSizer *LayoutArguments(LabelList& labels, TextList& texts);
    void Clear(TextList& texts);

    long idx_udn;
    long idx_fname;
    long idx_dtype;
    long idx_stype;
    long idx_sid;
    long idx_url;
    long idx_action;

    wxString serviceType;
    wxString action_name;
    wxString controlURL;
    wxString controlPath;
    int option;
    const struct tansu_cp_device *cp_device;
    const struct tansu_cp_service *cp_service;
    wxFlexGridSizer *in_sizer;
    wxFlexGridSizer *out_sizer;
    LabelList in_labels;
    TextList in_texts;
    LabelList out_labels;
    TextList out_texts;

    struct event_base *evbase;
    struct evhttp_connection *conn;
    struct evhttp_request *req;
    SoapResultList results;

public:
    virtual void OnListItemActivated(wxListEvent &event); // wxGlade: <event_handler>
    virtual void OnExecuteButton(wxCommandEvent &event); // wxGlade: <event_handler>
    virtual void OnCancelButton(wxCommandEvent &event); // wxGlade: <event_handler>
    virtual void OnClearButton(wxCommandEvent &event); // wxGlade: <event_handler>
    virtual void OnExitButton(wxCommandEvent &event); // wxGlade: <event_handler>

    void SoapHandler(struct evhttp_request *req);

    static void SetXML(wxTextCtrl& text_ctrl, struct tdom_doc *doc, struct evkeyvalq *headers = NULL);
    static void SetTextValue(wxTextCtrl& text_ctrl, const char *value);

}; // wxGlade: end class

#endif // SOAPFRAME_H
